<?php

     if(!$cboCustomer) {
         array_push($ActionResults, "Please enter Customer.");
         $intFailed++;
     }
     
     if(!$cboSalesChannel) {
         array_push($ActionResults, "Please select sales channel.");
         $intFailed++;
     }

//ShipAddress
     if(!$txtShipAddress) {
         array_push($ActionResults, "Please enter Address.");
         $intFailed++;
     }else{
         $txtShipAddress = ucwords(strtolower($txtShipAddress)); 
     }

//ShipCity
     if(!$txtShipCity) {
         array_push($ActionResults, "Please enter City.");
         $intFailed++;
     }else{
         $txtShipCity = ucwords(strtolower($txtShipCity)); 
     }

//ShipRegion
     if(!$txtShipRegion) {
         array_push($ActionResults, "Please enter Region.");
         $intFailed++;
     }else{
         $txtShipRegion = ucwords(strtolower($txtShipRegion)); 
     }

//ShipPostalCode
     if(!$txtShipPostalCode) {
         array_push($ActionResults, "Please enter Postal Code.");
         $intFailed++;
     }else{
         $txtShipPostalCode = strtoupper($txtShipPostalCode); 
     }

//ShipCountry
     if(!$txtShipCountry) {
         array_push($ActionResults, "Please enter Country.");
         $intFailed++;
     }

//ShipPhone
     if(!$txtShipPhone) {
         array_push($ActionResults, "Please enter Phone.");
         $intFailed++;
     }else{
         $txtShipPhone = ucwords(strtolower($txtShipPhone)); 
     }

//DeliveryAddress
     if(!$txtDeliveryAddress) {
         array_push($ActionResults, "Please enter Delivery Address.");
         $intFailed++;
     }else{
         $txtDeliveryAddress = ucwords(strtolower($txtDeliveryAddress)); 
     }

//DeliveryCity
     if(!$txtDeliveryCity) {
         array_push($ActionResults, "Please enter Delivery City.");
         $intFailed++;
     }else{
         $txtDeliveryCity = ucwords(strtolower($txtDeliveryCity)); 
     }

//DeliveryRegion
     if(!$txtDeliveryRegion) {
         array_push($ActionResults, "Please enter Delivery Region.");
         $intFailed++;
     }else{
         $txtDeliveryRegion = ucwords(strtolower($txtDeliveryRegion)); 
     }

//DeliveryPostalCode
     if(!$txtDeliveryPostalCode) {
         array_push($ActionResults, "Please enter Delivery Postal Code.");
         $intFailed++;
     }else{
         $txtDeliveryPostalCode = strtoupper($txtDeliveryPostalCode); 
     }
	 
//DeliveryCountry
     if(!$txtDeliveryCountry) {
         array_push($ActionResults, "Please enter Delivery Country.");
         $intFailed++;
     }
/*
     if(!$cboDeliveryCountry) {
         array_push($ActionResults, "Please enter Country.");
         $intFailed++;
     }
*/
     if($intFailed > 0){
         return(FALSE);
     }

	 $SCREEN = "DisplayOrderHeader";
	 
     if ($intOrderHeaderID){
     	$strSQL =  "SELECT * 
     				FROM tblOrderHeader 
     				WHERE tblOrderHeader.ID =  '$intOrderHeaderID'";
     	
     	
     	$qryOldOrderHeader = new MySqlResults($strSQL);
     	if($qryOldOrderHeader->myrow['OrderStatus'] != $cboOrderStatus)
     	{
      		$_REQUEST['txtNote'] = "Status changed from ".DisplayLookupValue("tblOrderStatus", "OrderStatus", $qryOldOrderHeader->myrow['OrderStatus'])." to ".DisplayLookupValue("tblOrderStatus", "OrderStatus", $cboOrderStatus);
     		include (MODULE . "/action/qryAddCustomerNotes.php");
     	}
        $strSQL = "Update tblOrderHeader
                     SET   tblOrderHeader.Customer =  '$cboCustomer'
                     	 , tblOrderHeader.SalesChannel =  '$cboSalesChannel'
                         , tblOrderHeader.OrderDate =  '".ReformatToMySqlDate($txtOrderDate)."'
                         , tblOrderHeader.ShippedDate =  '".ReformatToMySqlDate($txtShippedDate)."'
						 , tblOrderHeader.InvoiceDate =  '".ReformatToMySqlDate($txtInvoiceDate)."'
                         , tblOrderHeader.PaidDate =  '".ReformatToMySqlDate($txtPaidDate)."'
                         , tblOrderHeader.OrderStatus =  '$cboOrderStatus'
                         , tblOrderHeader.Courier =  '$cboCourier'
                         , tblOrderHeader.Freight =  '$txtFreight'
                         , tblOrderHeader.ShipName =  '$txtShipName'
                         , tblOrderHeader.ShipAddress =  '$txtShipAddress'
                         , tblOrderHeader.ShipAddress2 =  '$txtShipAddress2'
                         , tblOrderHeader.ShipCity =  '$txtShipCity'
                         , tblOrderHeader.ShipRegion =  '$txtShipRegion'
                         , tblOrderHeader.ShipPostalCode =  '$txtShipPostalCode'
                         , tblOrderHeader.ShipCountry =  '$txtShipCountry'
                         , tblOrderHeader.ShipPhone =  '$txtShipPhone'
						 , tblOrderHeader.DeliveryName =  '$txtDeliveryName'
                         , tblOrderHeader.DeliveryAddress =  '$txtDeliveryAddress'
                         , tblOrderHeader.DeliveryAddress2 =  '$txtDeliveryAddress2'
                         , tblOrderHeader.DeliveryCity =  '$txtDeliveryCity'
                         , tblOrderHeader.DeliveryRegion =  '$txtDeliveryRegion'
                         , tblOrderHeader.DeliveryPostalCode =  '$txtDeliveryPostalCode'
                         , tblOrderHeader.DeliveryCountry =  '$txtDeliveryCountry'
						 , tblOrderHeader.OtherInfo =  '$txtOtherInfo'
     "; 
        $strJoin = " WHERE ";
        $strSQL .= $strJoin."tblOrderHeader.ID =  '$intOrderHeaderID'";
        $strMessage = " Updated";
    }Else{

        $strSQL = "INSERT INTO tblOrderHeader
                     (     tblOrderHeader.Customer
                     	 , tblOrderHeader.SalesChannel
                         , tblOrderHeader.OrderDate
                         , tblOrderHeader.ShippedDate
						 , tblOrderHeader.InvoiceDate
                         , tblOrderHeader.PaidDate
                         , tblOrderHeader.OrderStatus
                         , tblOrderHeader.Courier
                         , tblOrderHeader.Freight
                         , tblOrderHeader.ShipName
                         , tblOrderHeader.ShipAddress
                         , tblOrderHeader.ShipAddress2
                         , tblOrderHeader.ShipCity
                         , tblOrderHeader.ShipRegion
                         , tblOrderHeader.ShipPostalCode
                         , tblOrderHeader.ShipCountry
                         , tblOrderHeader.ShipPhone
						 , tblOrderHeader.DeliveryName
                         , tblOrderHeader.DeliveryAddress
                         , tblOrderHeader.DeliveryAddress2
                         , tblOrderHeader.DeliveryCity
                         , tblOrderHeader.DeliveryRegion
                         , tblOrderHeader.DeliveryPostalCode
                         , tblOrderHeader.DeliveryCountry
                         , tblOrderHeader.OtherInfo
                     )Values( '$cboCustomer'
                     	 , $cboSalesChannel
                         , now()
                         , '".ReformatToMySqlDate($txtShippedDate)."'
						 , '".ReformatToMySqlDate($txtInvoiceDate)."'
                         , '".ReformatToMySqlDate($txtPaidDate)."'
                         , '$cboOrderStatus'
                         , '$cboCourier'
                         , '$txtFreight'
                         , '$txtShipName'
                         , '$txtShipAddress'
                         , '$txtShipAddress2'
                         , '$txtShipCity'
                         , '$txtShipRegion'
                         , '$txtShipPostalCode'
                         , '$txtShipCountry'
                         , '$txtShipPhone'
						 , '$txtDeliveryName'
                         , '$txtDeliveryAddress'
                         , '$txtDeliveryAddress2'
                         , '$txtDeliveryCity'
                         , '$txtDeliveryRegion'
                         , '$txtDeliveryPostalCode'
                         , '$txtDeliveryCountry'
                         , '$txtOtherInfo'
                       )";
        $strMessage = "added";
    }
    $strSQL .= ";";

         if (!include (MODULE . "/action/actMySqlResults")){
             array_push($ActionResults,"Failed To Add OrderHeader To Database");
			 $SCREEN = "EnterOrderHeader";
             return(false);
         }
?>
